<template>
  <div class="profile-container">
    <van-cell-group class="my-info" v-if="user">
        <van-cell title="单元格" value="内容" center class="base-info" :border='false'>
          <van-image
            class="avatar"
            slot="icon"
            round
            fit="cover"
            :src="USERINFO.photo"
          />
          <div slot="title" class="name">{{ USERINFO.name }}</div>
          <van-button size="small" round class="update-btn" to="/user/profile">编辑资料</van-button>
        </van-cell>

        <van-grid :border='false' class="data-info">
          <van-grid-item text="文字" class="data-info-item">
            <div slot="text" class="text-wrap" >
              <div class="count">{{ USERINFO.art_count }}</div>
              <div class="text">头条</div>
            </div>
          </van-grid-item>
          <van-grid-item text="文字" class="data-info-item">
            <div slot="text" class="text-wrap">
              <div class="count">{{ USERINFO.follow_count }}</div>
              <div class="text">关注</div>
            </div>
          </van-grid-item>
          <van-grid-item text="文字" class="data-info-item">
            <div slot="text" class="text-wrap">
              <div class="count">{{ USERINFO.fans_count }}</div>
              <div class="text">粉丝</div>
            </div>
          </van-grid-item>
          <van-grid-item text="文字" class="data-info-item">
            <div slot="text" class="text-wrap">
              <div class="count">{{ USERINFO.like_count }}</div>
              <div class="text">获赞</div>
            </div>
          </van-grid-item>
        </van-grid>
    </van-cell-group>

    <div class="not-login" v-else>
      <div class="mobile mb-4" @click="$router.push({name: 'login', query: {redirect: '/profile'}})">
        <img src="./mobile.png" alt="">
      </div>
      <div class="text">登录 / 注册</div>
    </div>

    <van-grid :column-num="2" class="nav-grid mb-4">
      <van-grid-item icon-prefix='icon' icon="shoucang" text="收藏" class="nav-grid-item"/>
      <van-grid-item icon-prefix='icon' icon="lishi" text="历史"   class="nav-grid-item"/>
    </van-grid>

    <van-cell title="消息通知" is-link to="" />
    <van-cell title="小智同学" is-link to="/user/chat" class="mb-4" />
    <van-cell title="退出登录"  class="logout-cell" v-if="user" @click="onlogout"/>

  </div>
</template>

<script>
import { mapState } from 'vuex'
import { getCurrentUser } from '@/api/user'
export default {
  name: 'ProfileIndex',
  components: {},
  props: {},
  data () {
    return {
      USERINFO: {}
    }
  },
  computed: {
    ...mapState(['user'])
  },
  mounted () {
    if (this.user) {
      this.getUserInfo()
    }
  },
  methods: {
    // 退出登录
    onlogout () {
      this.$dialog.confirm({
        title: '退出提示',
        message: '确定要退出吗?'
      }).then(() => {
        this.$store.commit('setUser', null)
      })
    },
    // 获取用户信息
    async getUserInfo () {
      const { data } = await getCurrentUser()
      this.USERINFO = data.data
    }
  }
}
</script>
<style lang='less' scoped>
.my-info {
  background-image: url("./banner.png");
  background-size: 100%;
  background-repeat: no-repeat;
  .base-info {
    background-color: unset;
    height: 115px;
    box-sizing: border-box;
    padding-top: 38px;
    padding-bottom: 11px;
    .avatar {
      width: 60px;
      height: 60px;
      border: 1px solid #fff;
      box-sizing: border-box;
      margin-right: 11px;
    }
    .name {
      font-size: 15px;
      color: #fff;
    }
    .update-btn {
      height: 16px;
      font-size: 10px;
      color: #666;
    }
  }
  .data-info {
    .data-info-item {
      height: 65px;
      color: #fff;
      .text-wrap {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        .count {
          font-size: 18px;
        }
        .text {
          font-size: 11px;
        }
      }
    }
  }
  /deep/ .van-grid-item__content {
    background-color: unset;
  }
}
/deep/ .nav-grid {
    .nav-grid-item {
      height: 70px;
      .icon {
        font-size: 22px;
      }
       .icon-shoucang {
        color: #eb5253;
      }
      .icon-lishi {
        color: #ff9d1d;
      }
      .van-grid-item__text {
        font-size: 14px;
        color: #333;
      }
    }
  }
  .logout-cell {
    text-align: center;
    color: #d86262;
  }

  .mb-4 {
    margin-bottom: 4px;
  }
  .not-login {
    height: 180px;
    background-image: url("./banner.png");
    background-size: 100%;
    background-repeat: no-repeat;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    .mobile {
      width: 60px;
      height: 60px;
      img {
        width: 100%;
      }
    }
    .text {
      font-size: 14px;
      color: #fff;
    }
  }
</style>
